import type { _RouteRecordBase } from 'vue-router';

//处理权限
export const hasPermission = (route: any, role: string) => {
  console.log('dsadasd', route.meta.auth, role);

  if (route.meta && route.meta.auth) {
    return route.meta.auth.includes(role);
  }
  //默认不设置权限
  return true;
};
// 菜单权限处理
export const filterAsyncRouter = (routerMap: any, roles: string) => {
  const accessedRouters = routerMap.filter((route: any) => {
    if (hasPermission(route, roles)) {
      if (route.children && route.children.length) {
        route.children = filterAsyncRouter(route.children, roles);
      }
      return true;
    }
    return false;
  });

  return accessedRouters;
};
